/**
 * @author denis.onishchenko@gmail.com
 */

package com.prapp.mediag;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.TextView;

public final class HtmlActivity extends Activity {

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.html);

        Bundle extras = getIntent().getExtras();
        int tabIndex = extras.getInt(PRApplication.TAB_INDEX);

        PRApplication application = (PRApplication) getApplication();

        Config.HtmlTab htmlTab = (Config.HtmlTab) application.getTab(tabIndex);

        String title = htmlTab.getName();
        if (title != null) {
            TextView textView = (TextView) findViewById(R.id.tvTitle);
            textView.setText(title);
        }

        String content = htmlTab.getContent();
        if (content != null) {
            WebView webView = (WebView) findViewById(R.id.wvContent);

            WebSettings settings = webView.getSettings();

            settings.setLoadsImagesAutomatically(true);
            settings.setDatabaseEnabled(false);
            settings.setGeolocationEnabled(false);
            settings.setJavaScriptEnabled(false);
            settings.setLightTouchEnabled(false);
            settings.setPluginsEnabled(false);
            settings.setSupportZoom(false);

            webView.loadDataWithBaseURL("", content.replaceAll("@images", "file:///android_asset"), "text/html", "UTF-8", "");
        }
    }
}
